﻿using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using WMS.FC.Domain.PersistenceObject.System;
using WMS.FC.Infrastructure.Common;

namespace WMS.FC.Infrastructure.POConfig.System
{
    public class RoleConfig : POBaseConfig<RolePO>
    {
        public override void InitializeData(EntityTypeBuilder<RolePO> builder)
        {
        }

        public override void MapColumn(EntityTypeBuilder<RolePO> builder, ref int index)
        {
            builder.HasComment("角色表");
            builder.Property(entity => entity.Name).ConfigColumn("NAME", "名称", 100, true).HasColumnOrder(index++);
            builder.HasMany(entity => entity.Menus).WithMany(entity => entity.Roles).UsingEntity(joinEntity => joinEntity.ToTable("S_ROLEMENU"));
            builder.HasMany(entity => entity.Users).WithMany(entity => entity.Roles).UsingEntity(joinEntity => joinEntity.ToTable("S_USERROLE"));
        }

        public override void MapIndex(EntityTypeBuilder<RolePO> builder)
        {
            builder.HasIndex(entity => entity.Name).HasDatabaseName($"UN_{TableName}_1").IsUnique();
        }
    }
}
